/**
 * 持久化 存储数据 及 读取数据
 *
 */
const prefix = `${window.location.origin}/`;

export default class Storage {
  static set(key: string, data: string) {
    window.localStorage.setItem(prefix + key, data);
  }

  static get(key: string) {
    if (window.localStorage.getItem(prefix + key))
      return window.localStorage.getItem(prefix + key);
    return false;
  }

  static clear() {
    window.localStorage.clear();
  }

  static remove(key: string) {
    window.localStorage.removeItem(prefix + key);
  }

  static setObjItem(key: string, data: object) {
    window.localStorage.setItem(prefix + key, JSON.stringify(data));
  }

  static getObjItem(key: string) {
    // @ts-ignore
    return JSON.parse(window.localStorage.getItem(prefix + key));
  }
}
